package com.example.demo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.demo.bean.CmsFood;
import com.example.demo.mapper.CmsFoodMapper;

@Service
public class CmsFoodService {
	@Autowired
	private CmsFoodMapper foodMapper;
	
	public int goumai(String id,int num1) {
		CmsFood m=foodMapper.selectByPrimaryKey(id);
		if(m.getNum()!=0) {
		m.num=m.getNum()-num1;
		foodMapper.updateByPrimaryKey(m);
		return 1;
	}
		else {return 0;}
	}
	public void caigou(String id) {
		CmsFood a=foodMapper.selectByPrimaryKey(id);
		a.num+=20;
		foodMapper.updateByPrimaryKey(a);
	}
	
	public CmsFood selectById(String id) {
		return foodMapper.selectByPrimaryKey(id);
	}

}